package com.ruoyi.cat.service.impl;

import com.ruoyi.cat.domain.CatActivityTable;
import com.ruoyi.cat.domain.CatArticlegiftTable;
import com.ruoyi.cat.domain.CatArticletaskTable;
import com.ruoyi.cat.service.ICatActivityTableService;
import com.ruoyi.cat.service.ICatArticlegiftTableService;
import com.ruoyi.cat.service.ICatArticletaskTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RichTextService {

  /*  @Autowired
    private RichTextRepository richTextRepository;*/

    @Autowired
    private ICatArticletaskTableService iCatArticletaskTableService;

    @Autowired
    private ICatActivityTableService iCatActivityTableService;

    public String generateVirtualPage(Long id) {
        CatArticletaskTable richText = iCatArticletaskTableService.selectCatArticletaskContentTableById(id);

        // 构建HTML模板
        StringBuilder htmlBuilder = new StringBuilder();
       /* htmlBuilder.append("<!DOCTYPE html>")
                .append("<html lang=\"zh-CN\">")
                .append("<head>")
                .append("<meta charset=\"UTF-8\">")
                .append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">")
                .append("<style>")
                .append("body { font-family: Arial, sans-serif; line-height: 1.6; margin: 0; padding: 20px; }")
                .append(".container { max-width: 800px; margin: 0 auto; }")
                .append(".content { background: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }")
                .append("</style>")
                .append("</head>")
                .append("<body>")
                .append("<div class=\"container\">")
                .append("<div class=\"content\">")
                .append("<div class=\"rich-content\">")
                .append(richText.getArticleContent())
                .append("</div>")
                .append("</div>")
                .append("</div>")
                .append("</body>")
                .append("</html>");*/
        htmlBuilder.append("<!DOCTYPE html>")
                .append("<html lang=\"zh-CN\">")
                .append("<head>")
                .append("<meta charset=\"UTF-8\">")
                .append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">")
                .append("</head>")
                .append("<body>")
                .append("<div id=\"content\">")
                .append(richText.getArticleContent())
                .append("</div>")
                .append("</body>")
                .append("</html>");
        return htmlBuilder.toString();
    }

    public String generateVirtualActivity(Long id) {
        CatActivityTable richText = iCatActivityTableService.selectCatActivityTableById1(id);
        // 构建HTML模板
        StringBuilder htmlBuilder = new StringBuilder();
        htmlBuilder.append("<!DOCTYPE html>")
                .append("<html lang=\"zh-CN\">")
                .append("<head>")
                .append("<meta charset=\"UTF-8\">")
                .append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">")
                .append("</head>")
                .append("<body>")
                .append("<div id=\"content\">")
                .append(richText.getActivityContent())
                .append("</div>")
                .append("</body>")
                .append("</html>");
        return htmlBuilder.toString();
    }


/*    // 添加转义 HTML 的函数
    private String escapeHtml(String s) {
        return s.replaceAll("&", "&amp;")
                .replaceAll("<", "&lt;")
                .replaceAll(">", "&gt;")
                .replaceAll("\"", "&quot;")
                .replaceAll("'", "&#39;");
    }*/
}